layui.define(['table', 'form','my_send'], function(exports){
    var $ = layui.$
    ,table = layui.table
    ,form = layui.form
    ,http_proxy = layui.http_proxy;
    function tdTitle(){
      $('th').each(function(index,element){
          $(element).attr('title',$(element).text());
      });
      $('td').each(function(index,element){
          $(element).attr('title',$(element).text());
      });
  };
    //车站故障统计
    table.render({
      elem: '#LAY-AnalysisOfAlarmData'
      , url: http_proxy('/alarm/allLineStationFaultStatistics') //模拟接口
      ,height: 'full-90' //高度最大化减去差值
      ,parseData:function(res){
        return{
          "code":0
          ,"count":''
          ,"data":res.data
          ,'msg':''
        }
      }
      ,cols: [[
        {field: 'id', title: '序号', width: 60}
        ,{field: 'station', title: '车站'}
        ,{field: 'deviceNum', title: '故障设备数'}
        ,{field: 'deviceSumNum', title: '设备总数'}
      ]]
      ,page: false
      ,limit: 10
      ,limits: [10, 15, 20, 25, 30]
      ,text: '暂无数据'
      ,done:function(res){
        tdTitle();
      }
    });
     //实时报警
     $.ajax({
      type : "get",
      async : false, //异步执行
      url : http_proxy("/devStatus/getStation"),
      dataType : "json", //返回数据形式为json
      success : function(data) {
        $.each(data.result,function(index,item){
          $('#alarmStations').append(new Option(item.label,item.label));
        })
        form.render('select');
      },
      error : function(errorMsg) {
        alert("请求数据失败");
      }
    });
    $.ajax({
        type : "get",
        async : false, //异步执行
        url : http_proxy("/devStatus/getSystems"),
        dataType : "json", //返回数据形式为json
        success : function(data) {
            $.each(data.result,function(index,item){
                $('#alarmSystems').append(new Option(item,index));
            })
            form.render('select');
        },
        error : function(errorMsg) {
            alert("请求数据失败");
        }
    });
    $.ajax({
        type : "get",
        async : false, //异步执行
        url : http_proxy("/devStatus/getAlarmLevel"),
        dataType : "json", //返回数据形式为json
        success : function(data) {
            $.each(data.result,function(index,item){
                $('#alarmLevels').append(new Option(item.label,item.value));
            })
            form.render('select');

        },
        error : function(errorMsg) {
            alert("请求数据失败");
        }
    });
      
     table.render({
        elem: '#allLineRealAlarm'
         ,url: http_proxy('/alarm/allLineRealAlarm')
         ,height: 'full-505' //高度最大化减去差值
         , method: 'post'
        ,contentType:"application/json"
        ,request: {
          pageName: 'pageNo', //页码的参数名称，默认：page
          limitName: 'pageSize' //每页数据量的参数名，默认：limit
        }
        ,parseData:function(res){
          return{
              "code":0
              ,"count":res.total
              ,"data":res.data
              ,'msg':''
          }
        }
        ,cols: [[
          {field: 'alarmTime',title: '报警生产时间',align: 'center'}
          ,{field: 'alarmStation', title: '车站',align: 'center'}
          ,{field: 'alarmSystem', title: '系统',align: 'center'}
          ,{field: 'rank', title: '优先级' ,align: 'center',width:80,templet:'#forTaskRank'}
          ,{field: 'alarmStatus', title: '状态',align: 'center',width:80,templet:'#forAlarmStatus'}
          ,{field: 'alarmMessage', title: '报警描述',align: 'center'}
        ]]
         ,page: true
         ,limit: 15
         ,limits: [10, 15, 20, 25, 30]
         ,text: {
             none:'暂无数据'
         }
         ,done:function(res){
          tdTitle();
        }
      });
 // 重要设备故障统计TOP10
 $.ajax({
    type : "get",
    async : false, //异步执行
    url: http_proxy('/alarm/inportDeviceTop'), //模拟接口
    dataType : "json", //返回数据形式为json
    success : function(data) {
      stationAlarmTop = data.data;
    },
    error : function(errorMsg) {
        alert("请求数据失败");
    }
  });
  //各专业故障统计
  var dataList=[];
  var dataValueList=new Array();
  $.ajax({
    type : "get",
    async : false, //异步执行
    url: http_proxy('/alarm/indexGetAlarmByType'),
    dataType : "json", //返回数据形式为json
    success : function(data) {
      alarmGradingStation = data.data;
      for(var i=0;i< alarmGradingStation.length;i++){
        dataList.push( alarmGradingStation[i].name);
        var map= new Map;
        map.name= alarmGradingStation[i].name;
        map.value= alarmGradingStation[i].value;
        dataValueList.push(map);
      }
    },
    error : function(errorMsg) {
        alert("请求数据失败");
    }
  });
  // 各级别故障统计
    var dataListFault=[];
    var dataValueListFault=new Array();
    $.ajax({
        type : "get",
        async : false, //异步执行
        url: http_proxy('/alarm/faultStatisticsAllLevels'),
        dataType : "json", //返回数据形式为json
        success : function(data) {
            faultStatisticsAllLevels = data.data;
            for(var i=0;i< faultStatisticsAllLevels.length;i++){
                dataListFault.push( faultStatisticsAllLevels[i].name);
                var map= new Map;
                map.name= faultStatisticsAllLevels[i].name;
                map.value= faultStatisticsAllLevels[i].value;
                dataValueListFault.push(map);
            }
        },
        error : function(errorMsg) {
            alert("请求数据失败");
        }
    });
// 重要设备故障统计TOP10
  var stationAlarm = echarts.init(document.getElementById('stationAlarm0'));
    option = {
      color: ['#3398DB'],
      tooltip: {
        trigger: 'axis',
        axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
        }
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        top:'18%',
        containLabel: true
      },
      xAxis: [{
        type: 'category',
        axisLine: {
          lineStyle: {
            color:'#3398DB',
            width:'1'
          }
        },
        axisLabel: {
          interval:0,
          rotate:40,
          textStyle: {
            color: '#606266'
          }
        },
        data:stationAlarmTop.xData,
        axisTick: {
          alignWithLabel: true,
          lineStyle:{
            color : '#3398DB',
          }
        }
      }],
      yAxis: [{
        name: "（数量）",
        type: 'value',
        nameTextStyle: {
          color: "#606266",
          fontSize: 16
        },
        type: 'value',
        axisLine: {
          lineStyle: {
            color:'#3398DB',
            width:'1'
          }
        },
        axisLabel: {
          textStyle: {
            color: '#606266'
          }
        },
      }],
      series: [{
        name: '站点',
        type: 'bar',
        barWidth: '50%',
        data:stationAlarmTop.yData
      }]
    };
  stationAlarm.setOption(option);
//各专业故障统计
  var stationAlarm = echarts.init(document.getElementById('stationAlarm1'));
  option = {
    tooltip: {
      show: true,
      trigger: 'item',
      formatter: "{b}: {c} ({d}%)"
    },
    legend: {
        orient: 'horizontal',
        left: "3%",
        textStyle: {
            color: '#606266',
        },
        // data:['AFC','ATS','PSD','ACS','FAS']
        data:dataList
    },
    series: [
      {
        type:'pie',
        selectedMode: 'single',
        radius : '65%',
        center: ['50%', '60%'],
        avoidLabelOverlap: false,
        color: ["#AF89D6", "#5ab6df", "#6a8bc0", "#4acacb", "#fe8676"],
        label: {
          normal: {
            formatter: "{b}\n{d}%",
            textStyle: {
              color: '#606266',
              fontWeight: "bold",
              fontSize: 12
            }
          }
        },
        itemStyle: {
          normal: {
            label: {
            show: true,
            formatter: "{b} : {c} ({d}%)"
            },
            labelLine: { show: true }
          }
        },
        data:dataValueList
      },
    ]
};
stationAlarm.setOption(option);

  var stationAlarm = echarts.init(document.getElementById('stationAlarm2'));
  option = {
    tooltip : {
        trigger: 'item',
        formatter: "{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'horizontal',
        left: 'left',
        textStyle: {
            color: '#606266',
        },
        data:dataListFault
    },
    series : [{
      type:'pie',
      radius : '65%',
      center: ['50%', '60%'],
      color: ["#DC143C","#436EEE", "#008fd1", "#e56c00"],
      data:dataValueListFault,
      itemStyle: {
        emphasis: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      },
    }]
};
  stationAlarm.setOption(option);
    exports('dataAnalysis', {})
  });